from bs4 import BeautifulSoup
import re
import urllib.request,urllib.error
import xlwt
import sqlite3
def main():
    baseurl = "https://www.tute.edu.cn/xysh/yxtzsd.htm"
    #1.爬取网页
    datalist = getData(baseurl)
    savepath = ".\\用户保存图片.xls"
    #3.保存数据
    #saveData(savepath)
    askURL("https://www.tute.edu.cn/xysh/yxtzsd.htm")


#爬取网页
def getData(baseurl):
    datalist = []
    #2.解析数据
    return datalist


#得到指定一个URL的网页内容
def askURL(url):
    head = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"}
    request = urllib.request.Request(url,headers=head)
    html = ""
    try:
        response = urllib.request.urlopen(request)
        html = response.read().decode("utf-8")
        print(html)
    except urllib.error.URLError as e:
        if hasattr(e,"code"):
            print(e.code)
        if hasattr(e,"reason"):
            print(e.reason)
    #return html



#3.保存数据
def saveData(savepath):
    print("save....")



if __name__=="__main__":
    main()